<template>
  <div>
    <el-card>
      <div slot="header">
        <div class="header">
          <span>销售额类别占比</span>
          <div>
            <el-checkbox-group v-model="checkboxGroup1">
              <el-checkbox-button v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox-button>
            </el-checkbox-group>
          </div>
        </div>
      </div>
      <div>
        <div class="myecharts" ref="myecharts"></div>
      </div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
const cityOptions = ['上海', '北京', '广州', '深圳']
export default {
  name: 'Category',
  data() {
    return {
      checkboxGroup1: [],
      cities: cityOptions,
    }
  },
  mounted() {
    let myecharts = echarts.init(this.$refs.myecharts)
    myecharts.setOption({
      title: {
        text: '视频',
        subtext: 1234,
        left: 'center',
        top: 'center',
      },
      tooltip: {
        trigger: 'item',
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2,
          },
          label: {
            show: true,
            position: 'outside',
          },
          labelLine: {
            show: true,
          },
          data: [
            { value: 1048, name: 'Search Engine' },
            { value: 735, name: 'Direct' },
            { value: 580, name: 'Email' },
            { value: 484, name: 'Union Ads' },
            { value: 300, name: 'Video Ads' },
          ],
        },
      ],
    })
    myecharts.on('mouseover', (params) => {
      console.log(params)
      myecharts.setOption({
        title: {
          text: params.data.name,
          subtext: params.data.value,
        },
      })
    })
  },
}
</script>

<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.myecharts {
  width: 100%;
  height: 300px;
}
</style>